// import Vue from 'vue'
// import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

// Vue.use(VueRouter)

// const routes = [
//   {
//     path: '/',
//     name: 'home',
//     component: Home
//   },
//   {
//     path: '/about',
//     name: 'about',
//     // route level code-splitting
//     // this generates a separate chunk (about.[hash].js) for this route
//     // which is lazy-loaded when the route is visited.
//     component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
//   }
// ]

// const router = new VueRouter({
//   mode: 'history',
//   base: process.env.BASE_URL,
//   routes
// })

// export default router


import Vue from 'vue'
import Router from 'vue-router'

import Movie from '../components/Movie'
import TV from '../components/TV'
import TV2 from '../components/TV2'
import TV3 from '../components/TV3'
import MovieDetail from '../components/MovieDetail.vue'
import Page404 from '../components/Page404'
import detail from "../components/detail.vue"
import About from "../components/About.vue"

Vue.use(Router)

const routes = [
    {
        path: '/',
        // redirect: '/movie',
        // redirect: {name: "movie"},
        redirect: (to) => {
            return 3 > 5 ? "/movie" : "/tv"
        }
    },
    {
        name: 'movie',
        alias: "movie2",
        path: '/movie',
        component: Movie,
        children: [
            {
                name:'moviedetail',
                path:'detail/:id/:nm',
                component: MovieDetail
            }
        ]
    },
    {
        path: '/tv',
        components: {
            default: TV,
            tv2: TV2,
            tv3: TV3
        },
        beforeEnter:(to, from, next)=>{
            next()
        },
    },
    {
        path: '',
        component: TV
    },
    {
        path: '*',
        component: Page404
    },
    {
        name: "detail",
        props: true,
        path: "/detail/:id",
        component: detail,

    },
    {
        name: "about",
        path: "/about",
        component: About,
        beforeEnter:(to, from, next)=>{
            if(confirm('你真的要jin ru吗？')) {
                next()
            }
        },
    }
]


const router = new Router ({
    routes ,
    // base : process.env.BASE_URL
})

router.beforeEach((to, from, next ) => {
    // console.log(0);
    // if(from.name === 'about'){
    //     if(confirm('你真的要离开吗？')) {
    //         next()
    //     }
    // }else if(to.name === 'about'){
    //     if(confirm('你真的要进入吗？')) {
    //         next()
    //     }
    // }else{
    //     next()
    // }
    console.log("beforeEach");
    next()
})
router.beforeResolve((to, from, next)=>{
    console.log("beforeResolve");
    next()
})
router.afterEach((to, from)=>{
    //善后工作
})
export default router